import QtQuick 1.0
import Box2D 1.0


Component{
	id: component

	Body{
		id: body
		height: 20
		width: 40
		bodyType: Body.Dynamic
		Component.onCompleted: timer.start()


		signal exploded()

		fixtures: Box{
			anchors.fill: parent
			density: 10;
			friction: 0.4;
			restitution: 0.5;
		}

		Image {
			id: image
			anchors.fill: parent
			source: "qrc:///qml/images/dynamite.png"
		}


		Charge{
			id: charge
		}

		Timer{
			id: timer
			interval: 3000
			onTriggered: {

				for(var i = 0; i < 5; i++){
					var t = charge.createObject(body.parent)
					t.x = body.x
					t.y = body.y
				}


				body.state  = "explode"
			}
		}




		Timer{
			id: destroy
			interval: 100
			onTriggered: {
				exploded()
				image.visible = false
				body.parent.unregisterBody(body)
				body.destroy(1000)
			}
		}

		states: [
			State {
				name: "explode"
				PropertyChanges {target: image; source: "qrc:///qml/images/explosion.png"; anchors.margins: -100}
				PropertyChanges {target: destroy; running: true}
			}
		]
	}
}


